package org.infodavid.common.model;

import java.util.ArrayList;
import java.util.List;

import org.infodavid.common.IBuilder;
import org.infodavid.common.ejb.TemplateCategoryBean;

/**
 * The Class TemplateCategoryTest.
 */
public class TemplateCategoryTest extends AbstractBeanTest<ITemplateCategory> {

	/**
	 * Instantiates a new category test.
	 * @param mainTest the main test
	 */
	public TemplateCategoryTest(final AbstractPersistenceTest mainTest) {
		super(mainTest);
	}

	/**
	 * Instantiates a new category test.
	 */
	public TemplateCategoryTest() {
		super();
	}

	/**
	 * Populate.
	 * @param count the count
	 * @return the collection< test data>
	 * @throws Exception the exception
	 */
	@Override
	protected List<ITemplateCategory> doCreate(final int count) throws Exception {
		final IBuilder<ITemplateCategory> builder =
		    ModelFactory.getInstance().getBuilder(ITemplateCategory.class);
		final List<ITemplateCategory> items = new ArrayList<ITemplateCategory>(count);
		ITemplateCategory parent = null;
		ITemplateCategory item;

		for (int i = 0; i < count; i++) {
			item = builder.create();

			item.setName("item-" + System.nanoTime());

			if (i == 0) {
				parent = item;
			}
			else {
				parent.addSubCategory(item);
			}

			items.add(item);
		}

		return items;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.model.AbstractBeanTest#getEntityClass()
	 */
	@Override
	public Class<TemplateCategoryBean> getEntityClass() {
		return TemplateCategoryBean.class;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.model.AbstractBeanTest#getEntityName()
	 */
	@Override
	public String getEntityName() {
		return ITemplateCategory.class.getSimpleName();
	}
}
